import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainForm {

	JFrame frame;
	ResultForm resultForm;
	private JTextField textFieldPrio;
	private JTextField textFieldGen;
	private JComboBox<String> comboBoxName;
	private JCheckBox checkBoxWish1;
	private JCheckBox checkBoxWish2;
	private JCheckBox checkBoxWish3;
	private JCheckBox checkBoxWish4;
	private JCheckBox checkBoxWish5;
	private JCheckBox checkBoxWish6;
	private JCheckBox checkBoxWish7;
	private JCheckBox checkBoxWish8;
	private JCheckBox checkBoxWish9;
	private JCheckBox checkBoxWish10;
	private JCheckBox checkBoxWish11;
	private JCheckBox checkBoxWish12;
	private JCheckBox checkBoxWish13;
	private JCheckBox checkBoxWish14;
	private JCheckBox checkBoxWish15;
	private JCheckBox checkBoxWish16;
	private JCheckBox checkBoxWish17;
	private JCheckBox checkBoxWish18;
	private JCheckBox checkBoxWish19;
	private JCheckBox checkBoxWish20;
	private JCheckBox checkBoxWish21;
	private JCheckBox checkBoxWish22;
	private JCheckBox checkBoxWish23;
	private JCheckBox checkBoxWish24;
	private JCheckBox checkBoxWish25;
	private JCheckBox checkBoxWish26;
	private JCheckBox checkBoxWish27;
	private JCheckBox checkBoxWish28;
	private JCheckBox checkBoxWish29;
	private JCheckBox checkBoxWish30;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainForm window = new MainForm();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainForm() {
		initialize();
	}
	
	private void clearInfo() {
		textFieldPrio.setText("");
		checkBoxWish1.setSelected(false);
		checkBoxWish2.setSelected(false);
		checkBoxWish3.setSelected(false);
		checkBoxWish4.setSelected(false);
		checkBoxWish5.setSelected(false);
		checkBoxWish6.setSelected(false);
		checkBoxWish7.setSelected(false);
		checkBoxWish8.setSelected(false);
		checkBoxWish9.setSelected(false);
		checkBoxWish10.setSelected(false);
		checkBoxWish11.setSelected(false);
		checkBoxWish12.setSelected(false);
		checkBoxWish13.setSelected(false);
		checkBoxWish14.setSelected(false);
		checkBoxWish15.setSelected(false);
		checkBoxWish16.setSelected(false);
		checkBoxWish17.setSelected(false);
		checkBoxWish18.setSelected(false);
		checkBoxWish19.setSelected(false);
		checkBoxWish20.setSelected(false);
		checkBoxWish21.setSelected(false);
		checkBoxWish22.setSelected(false);
		checkBoxWish23.setSelected(false);
		checkBoxWish24.setSelected(false);
		checkBoxWish25.setSelected(false);
		checkBoxWish26.setSelected(false);
		checkBoxWish27.setSelected(false);
		checkBoxWish28.setSelected(false);
		checkBoxWish29.setSelected(false);
		checkBoxWish30.setSelected(false);
		
	}
	private void updateInfo() {
		String name = null;
		try {
			name = comboBoxName.getSelectedItem().toString();
		} catch (Exception e) {
			clearInfo();
			return;
		}
		Tutor teacher = Adapter.getTutor(name);
		boolean[] wishes = teacher.getWishes();
		
		textFieldPrio.setText(String.valueOf(teacher.getPriority()));
		checkBoxWish1.setSelected(wishes[0]);
		checkBoxWish2.setSelected(wishes[1]);
		checkBoxWish3.setSelected(wishes[2]);
		checkBoxWish4.setSelected(wishes[3]);
		checkBoxWish5.setSelected(wishes[4]);
		checkBoxWish6.setSelected(wishes[5]);
		checkBoxWish7.setSelected(wishes[6]);
		checkBoxWish8.setSelected(wishes[7]);
		checkBoxWish9.setSelected(wishes[8]);
		checkBoxWish10.setSelected(wishes[9]);
		checkBoxWish11.setSelected(wishes[10]);
		checkBoxWish12.setSelected(wishes[11]);
		checkBoxWish13.setSelected(wishes[12]);
		checkBoxWish14.setSelected(wishes[13]);
		checkBoxWish15.setSelected(wishes[14]);
		checkBoxWish16.setSelected(wishes[15]);
		checkBoxWish17.setSelected(wishes[16]);
		checkBoxWish18.setSelected(wishes[17]);
		checkBoxWish19.setSelected(wishes[18]);
		checkBoxWish20.setSelected(wishes[19]);
		checkBoxWish21.setSelected(wishes[20]);
		checkBoxWish22.setSelected(wishes[21]);
		checkBoxWish23.setSelected(wishes[22]);
		checkBoxWish24.setSelected(wishes[23]);
		checkBoxWish25.setSelected(wishes[24]);
		checkBoxWish26.setSelected(wishes[25]);
		checkBoxWish27.setSelected(wishes[26]);
		checkBoxWish28.setSelected(wishes[27]);
		checkBoxWish29.setSelected(wishes[28]);
		checkBoxWish30.setSelected(wishes[29]);
	}
	
	private void addTeacher() {
		String name = comboBoxName.getSelectedItem().toString();
		comboBoxName.addItem(name);
		Adapter.addTutor(new Tutor(name));
		updateInfo();
	}
	
	private void delTeacher() {
		if (comboBoxName.getItemCount() > 0) {
			String name = comboBoxName.getSelectedItem().toString();			
			Adapter.delTutor(name);
			comboBoxName.removeItem(comboBoxName.getSelectedItem());
			updateInfo();			
		}
	}
	
	private void editTeacher() {
		if (comboBoxName.getItemCount() >= 1) {
			boolean[] wishes = new boolean[30];
			String name = comboBoxName.getSelectedItem().toString();			
			Tutor teacher = Adapter.getTutor(name);
			String prio = textFieldPrio.getText();
			
			wishes[0] = checkBoxWish1.isSelected();
			wishes[1] = checkBoxWish2.isSelected();
			wishes[2] = checkBoxWish3.isSelected();
			wishes[3] = checkBoxWish4.isSelected();
			wishes[4] = checkBoxWish5.isSelected();
			wishes[5] = checkBoxWish6.isSelected();
			wishes[6] = checkBoxWish7.isSelected();
			wishes[7] = checkBoxWish8.isSelected();
			wishes[8] = checkBoxWish9.isSelected();
			wishes[9] = checkBoxWish10.isSelected();
			wishes[10] = checkBoxWish11.isSelected();
			wishes[11] = checkBoxWish12.isSelected();
			wishes[12] = checkBoxWish13.isSelected();
			wishes[13] = checkBoxWish14.isSelected();
			wishes[14] = checkBoxWish15.isSelected();
			wishes[15] = checkBoxWish16.isSelected();
			wishes[16] = checkBoxWish17.isSelected();
			wishes[17] = checkBoxWish18.isSelected();
			wishes[18] = checkBoxWish19.isSelected();
			wishes[19] = checkBoxWish20.isSelected();
			wishes[20] = checkBoxWish21.isSelected();
			wishes[21] = checkBoxWish22.isSelected();
			wishes[22] = checkBoxWish23.isSelected();
			wishes[23] = checkBoxWish24.isSelected();
			wishes[24] = checkBoxWish25.isSelected();
			wishes[25] = checkBoxWish26.isSelected();
			wishes[26] = checkBoxWish27.isSelected();
			wishes[27] = checkBoxWish28.isSelected();
			wishes[28] = checkBoxWish29.isSelected();
			wishes[29] = checkBoxWish30.isSelected();
			
			try {
				teacher.setPriority(Double.valueOf(prio));
			} catch (Exception e) {
				JOptionPane.showMessageDialog(frame, "������� ����� �� 0 �� 1", "������������ ���� ����������", JOptionPane.ERROR_MESSAGE);
				return;
			}
			teacher.setWishes(wishes);
			
			Adapter.setTutor(teacher);
						
			updateInfo();			
		}
	}
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {		
		frame = new JFrame();
		frame.setResizable(false);
		frame.setBounds(100, 100, 453, 366);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("436px:grow"),},
			new RowSpec[] {
				RowSpec.decode("280px"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		JPanel panelTeacher = new JPanel();
		frame.getContentPane().add(panelTeacher, "1, 1, fill, fill");
		panelTeacher.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(139dlu;default)"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				ColumnSpec.decode("max(4dlu;default)"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		JLabel labelName = new JLabel("\u0424.\u0418.\u041E.:");
		panelTeacher.add(labelName, "2, 2, left, center");
		
		final JButton buttonAddName = new JButton("V");
		
		comboBoxName = new JComboBox<String>();
		comboBoxName.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {
				if (!comboBoxName.isEditable()) {
					updateInfo();
				}
			}
		});
		panelTeacher.add(comboBoxName, "4, 2, fill, default");

		buttonAddName.setEnabled(false);
		panelTeacher.add(buttonAddName, "6, 2, left, default");
		
		JLabel labelPrio = new JLabel("\u041F\u0440\u0438\u043E\u0440\u0438\u0442\u0435\u0442:");
		panelTeacher.add(labelPrio, "2, 4, left, center");
		
		textFieldPrio = new JTextField();
		textFieldPrio.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				editTeacher();
			}
		});
		panelTeacher.add(textFieldPrio, "4, 4, left, default");
		textFieldPrio.setColumns(15);
		
		JLabel labelWishes = new JLabel("\u041F\u043E\u0436\u0435\u043B\u0430\u043D\u0438\u044F:");
		panelTeacher.add(labelWishes, "2, 6, left, top");
		
		JPanel panelWishes = new JPanel();
		panelTeacher.add(panelWishes, "4, 6, left, top");
		GridBagLayout gbl_panelWishes = new GridBagLayout();
		gbl_panelWishes.columnWidths = new int[] {30, 30, 30, 30, 30, 30, 30};
		gbl_panelWishes.rowHeights = new int[] {30, 30, 30, 30, 30, 30};
		gbl_panelWishes.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
		gbl_panelWishes.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
		panelWishes.setLayout(gbl_panelWishes);
		
		JLabel labelD1 = new JLabel("\u041F\u043D");
		GridBagConstraints gbc_labelD1 = new GridBagConstraints();
		gbc_labelD1.insets = new Insets(0, 0, 5, 5);
		gbc_labelD1.gridx = 1;
		gbc_labelD1.gridy = 0;
		panelWishes.add(labelD1, gbc_labelD1);
		
		JLabel labelD2 = new JLabel("\u0412\u0442");
		GridBagConstraints gbc_labelD2 = new GridBagConstraints();
		gbc_labelD2.insets = new Insets(0, 0, 5, 5);
		gbc_labelD2.gridx = 2;
		gbc_labelD2.gridy = 0;
		panelWishes.add(labelD2, gbc_labelD2);
		
		JLabel labelD3 = new JLabel("\u0421\u0440");
		GridBagConstraints gbc_labelD3 = new GridBagConstraints();
		gbc_labelD3.insets = new Insets(0, 0, 5, 5);
		gbc_labelD3.gridx = 3;
		gbc_labelD3.gridy = 0;
		panelWishes.add(labelD3, gbc_labelD3);
		
		JLabel labelD4 = new JLabel("\u0427\u0442");
		GridBagConstraints gbc_labelD4 = new GridBagConstraints();
		gbc_labelD4.insets = new Insets(0, 0, 5, 5);
		gbc_labelD4.gridx = 4;
		gbc_labelD4.gridy = 0;
		panelWishes.add(labelD4, gbc_labelD4);
		
		JLabel labelD5 = new JLabel("\u041F\u0442");
		GridBagConstraints gbc_labelD5 = new GridBagConstraints();
		gbc_labelD5.insets = new Insets(0, 0, 5, 5);
		gbc_labelD5.gridx = 5;
		gbc_labelD5.gridy = 0;
		panelWishes.add(labelD5, gbc_labelD5);
		
		JLabel labelD6 = new JLabel("\u0421\u0431");
		GridBagConstraints gbc_labelD6 = new GridBagConstraints();
		gbc_labelD6.insets = new Insets(0, 0, 5, 0);
		gbc_labelD6.gridx = 6;
		gbc_labelD6.gridy = 0;
		panelWishes.add(labelD6, gbc_labelD6);
		
		JLabel labelL1 = new JLabel("1");
		GridBagConstraints gbc_labelL1 = new GridBagConstraints();
		gbc_labelL1.insets = new Insets(0, 0, 5, 5);
		gbc_labelL1.gridx = 0;
		gbc_labelL1.gridy = 1;
		panelWishes.add(labelL1, gbc_labelL1);
		
		checkBoxWish1 = new JCheckBox("");
		checkBoxWish1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
			}
		});
		checkBoxWish1.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});

		GridBagConstraints gbc_checkBoxWish1 = new GridBagConstraints();
		gbc_checkBoxWish1.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish1.gridx = 1;
		gbc_checkBoxWish1.gridy = 1;
		panelWishes.add(checkBoxWish1, gbc_checkBoxWish1);
		
		checkBoxWish6 = new JCheckBox("");
		checkBoxWish6.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish6 = new GridBagConstraints();
		gbc_checkBoxWish6.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish6.gridx = 2;
		gbc_checkBoxWish6.gridy = 1;
		panelWishes.add(checkBoxWish6, gbc_checkBoxWish6);
		
		checkBoxWish11 = new JCheckBox("");
		checkBoxWish11.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish11 = new GridBagConstraints();
		gbc_checkBoxWish11.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish11.gridx = 3;
		gbc_checkBoxWish11.gridy = 1;
		panelWishes.add(checkBoxWish11, gbc_checkBoxWish11);
		
		checkBoxWish16 = new JCheckBox("");
		checkBoxWish16.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish16 = new GridBagConstraints();
		gbc_checkBoxWish16.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish16.gridx = 4;
		gbc_checkBoxWish16.gridy = 1;
		panelWishes.add(checkBoxWish16, gbc_checkBoxWish16);
		
		checkBoxWish21 = new JCheckBox("");
		checkBoxWish21.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish21 = new GridBagConstraints();
		gbc_checkBoxWish21.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish21.gridx = 5;
		gbc_checkBoxWish21.gridy = 1;
		panelWishes.add(checkBoxWish21, gbc_checkBoxWish21);
		
		checkBoxWish26 = new JCheckBox("");
		checkBoxWish26.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish26 = new GridBagConstraints();
		gbc_checkBoxWish26.insets = new Insets(0, 0, 5, 0);
		gbc_checkBoxWish26.gridx = 6;
		gbc_checkBoxWish26.gridy = 1;
		panelWishes.add(checkBoxWish26, gbc_checkBoxWish26);
		
		JLabel labelL2 = new JLabel("2");
		GridBagConstraints gbc_labelL2 = new GridBagConstraints();
		gbc_labelL2.insets = new Insets(0, 0, 5, 5);
		gbc_labelL2.gridx = 0;
		gbc_labelL2.gridy = 2;
		panelWishes.add(labelL2, gbc_labelL2);
		
		checkBoxWish2 = new JCheckBox("");
		checkBoxWish2.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish2 = new GridBagConstraints();
		gbc_checkBoxWish2.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish2.gridx = 1;
		gbc_checkBoxWish2.gridy = 2;
		panelWishes.add(checkBoxWish2, gbc_checkBoxWish2);
		
		checkBoxWish7 = new JCheckBox("");
		checkBoxWish7.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish7 = new GridBagConstraints();
		gbc_checkBoxWish7.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish7.gridx = 2;
		gbc_checkBoxWish7.gridy = 2;
		panelWishes.add(checkBoxWish7, gbc_checkBoxWish7);
		
		checkBoxWish12 = new JCheckBox("");
		checkBoxWish12.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish12 = new GridBagConstraints();
		gbc_checkBoxWish12.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish12.gridx = 3;
		gbc_checkBoxWish12.gridy = 2;
		panelWishes.add(checkBoxWish12, gbc_checkBoxWish12);
		
		checkBoxWish17 = new JCheckBox("");
		checkBoxWish17.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish17 = new GridBagConstraints();
		gbc_checkBoxWish17.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish17.gridx = 4;
		gbc_checkBoxWish17.gridy = 2;
		panelWishes.add(checkBoxWish17, gbc_checkBoxWish17);
		
		checkBoxWish22 = new JCheckBox("");
		checkBoxWish22.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish22 = new GridBagConstraints();
		gbc_checkBoxWish22.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish22.gridx = 5;
		gbc_checkBoxWish22.gridy = 2;
		panelWishes.add(checkBoxWish22, gbc_checkBoxWish22);
		
		checkBoxWish27 = new JCheckBox("");
		checkBoxWish27.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish27 = new GridBagConstraints();
		gbc_checkBoxWish27.insets = new Insets(0, 0, 5, 0);
		gbc_checkBoxWish27.gridx = 6;
		gbc_checkBoxWish27.gridy = 2;
		panelWishes.add(checkBoxWish27, gbc_checkBoxWish27);
		
		JLabel labelL3 = new JLabel("3");
		GridBagConstraints gbc_labelL3 = new GridBagConstraints();
		gbc_labelL3.insets = new Insets(0, 0, 5, 5);
		gbc_labelL3.gridx = 0;
		gbc_labelL3.gridy = 3;
		panelWishes.add(labelL3, gbc_labelL3);
		
		checkBoxWish3 = new JCheckBox("");
		checkBoxWish3.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish3 = new GridBagConstraints();
		gbc_checkBoxWish3.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish3.gridx = 1;
		gbc_checkBoxWish3.gridy = 3;
		panelWishes.add(checkBoxWish3, gbc_checkBoxWish3);
		
		checkBoxWish8 = new JCheckBox("");
		checkBoxWish8.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish8 = new GridBagConstraints();
		gbc_checkBoxWish8.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish8.gridx = 2;
		gbc_checkBoxWish8.gridy = 3;
		panelWishes.add(checkBoxWish8, gbc_checkBoxWish8);
		
		checkBoxWish13 = new JCheckBox("");
		checkBoxWish13.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish13 = new GridBagConstraints();
		gbc_checkBoxWish13.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish13.gridx = 3;
		gbc_checkBoxWish13.gridy = 3;
		panelWishes.add(checkBoxWish13, gbc_checkBoxWish13);
		
		checkBoxWish18 = new JCheckBox("");
		checkBoxWish18.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish18 = new GridBagConstraints();
		gbc_checkBoxWish18.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish18.gridx = 4;
		gbc_checkBoxWish18.gridy = 3;
		panelWishes.add(checkBoxWish18, gbc_checkBoxWish18);
		
		checkBoxWish23 = new JCheckBox("");
		checkBoxWish23.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish23 = new GridBagConstraints();
		gbc_checkBoxWish23.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish23.gridx = 5;
		gbc_checkBoxWish23.gridy = 3;
		panelWishes.add(checkBoxWish23, gbc_checkBoxWish23);
		
		checkBoxWish28 = new JCheckBox("");
		checkBoxWish28.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish28 = new GridBagConstraints();
		gbc_checkBoxWish28.insets = new Insets(0, 0, 5, 0);
		gbc_checkBoxWish28.gridx = 6;
		gbc_checkBoxWish28.gridy = 3;
		panelWishes.add(checkBoxWish28, gbc_checkBoxWish28);
		
		JLabel labelL4 = new JLabel("4");
		GridBagConstraints gbc_labelL4 = new GridBagConstraints();
		gbc_labelL4.insets = new Insets(0, 0, 5, 5);
		gbc_labelL4.gridx = 0;
		gbc_labelL4.gridy = 4;
		panelWishes.add(labelL4, gbc_labelL4);
		
		checkBoxWish4 = new JCheckBox("");
		checkBoxWish4.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish4 = new GridBagConstraints();
		gbc_checkBoxWish4.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish4.gridx = 1;
		gbc_checkBoxWish4.gridy = 4;
		panelWishes.add(checkBoxWish4, gbc_checkBoxWish4);
		
		checkBoxWish9 = new JCheckBox("");
		checkBoxWish9.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish9 = new GridBagConstraints();
		gbc_checkBoxWish9.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish9.gridx = 2;
		gbc_checkBoxWish9.gridy = 4;
		panelWishes.add(checkBoxWish9, gbc_checkBoxWish9);
		
		checkBoxWish14 = new JCheckBox("");
		checkBoxWish14.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish14 = new GridBagConstraints();
		gbc_checkBoxWish14.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish14.gridx = 3;
		gbc_checkBoxWish14.gridy = 4;
		panelWishes.add(checkBoxWish14, gbc_checkBoxWish14);
		
		checkBoxWish19 = new JCheckBox("");
		checkBoxWish19.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish19 = new GridBagConstraints();
		gbc_checkBoxWish19.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish19.gridx = 4;
		gbc_checkBoxWish19.gridy = 4;
		panelWishes.add(checkBoxWish19, gbc_checkBoxWish19);
		
		checkBoxWish24 = new JCheckBox("");
		checkBoxWish24.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish24 = new GridBagConstraints();
		gbc_checkBoxWish24.insets = new Insets(0, 0, 5, 5);
		gbc_checkBoxWish24.gridx = 5;
		gbc_checkBoxWish24.gridy = 4;
		panelWishes.add(checkBoxWish24, gbc_checkBoxWish24);

		checkBoxWish29 = new JCheckBox("");
		checkBoxWish29.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish29 = new GridBagConstraints();
		gbc_checkBoxWish29.insets = new Insets(0, 0, 5, 0);
		gbc_checkBoxWish29.gridx = 6;
		gbc_checkBoxWish29.gridy = 4;
		panelWishes.add(checkBoxWish29, gbc_checkBoxWish29);
		
		JLabel labelL5 = new JLabel("5");
		GridBagConstraints gbc_labelL5 = new GridBagConstraints();
		gbc_labelL5.insets = new Insets(0, 0, 0, 5);
		gbc_labelL5.gridx = 0;
		gbc_labelL5.gridy = 5;
		panelWishes.add(labelL5, gbc_labelL5);
		
		checkBoxWish5 = new JCheckBox("");
		checkBoxWish5.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish5 = new GridBagConstraints();
		gbc_checkBoxWish5.insets = new Insets(0, 0, 0, 5);
		gbc_checkBoxWish5.gridx = 1;
		gbc_checkBoxWish5.gridy = 5;
		panelWishes.add(checkBoxWish5, gbc_checkBoxWish5);
		
		checkBoxWish10 = new JCheckBox("");
		checkBoxWish10.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish10 = new GridBagConstraints();
		gbc_checkBoxWish10.insets = new Insets(0, 0, 0, 5);
		gbc_checkBoxWish10.gridx = 2;
		gbc_checkBoxWish10.gridy = 5;
		panelWishes.add(checkBoxWish10, gbc_checkBoxWish10);
		
		checkBoxWish15 = new JCheckBox("");
		checkBoxWish15.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish15 = new GridBagConstraints();
		gbc_checkBoxWish15.insets = new Insets(0, 0, 0, 5);
		gbc_checkBoxWish15.gridx = 3;
		gbc_checkBoxWish15.gridy = 5;
		panelWishes.add(checkBoxWish15, gbc_checkBoxWish15);
		
		checkBoxWish20 = new JCheckBox("");
		checkBoxWish20.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish20 = new GridBagConstraints();
		gbc_checkBoxWish20.insets = new Insets(0, 0, 0, 5);
		gbc_checkBoxWish20.gridx = 4;
		gbc_checkBoxWish20.gridy = 5;
		panelWishes.add(checkBoxWish20, gbc_checkBoxWish20);
		
		checkBoxWish25 = new JCheckBox("");
		checkBoxWish25.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish25 = new GridBagConstraints();
		gbc_checkBoxWish25.insets = new Insets(0, 0, 0, 5);
		gbc_checkBoxWish25.gridx = 5;
		gbc_checkBoxWish25.gridy = 5;
		panelWishes.add(checkBoxWish25, gbc_checkBoxWish25);
		
		checkBoxWish30 = new JCheckBox("");
		checkBoxWish30.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent arg0) {
				editTeacher();
			}
		});
		GridBagConstraints gbc_checkBoxWish30 = new GridBagConstraints();
		gbc_checkBoxWish30.gridx = 6;
		gbc_checkBoxWish30.gridy = 5;
		panelWishes.add(checkBoxWish30, gbc_checkBoxWish30);
		
		final JButton buttonGen = new JButton("\u0413\u0435\u043D\u0435\u0440\u0430\u0446\u0438\u044F");
		buttonGen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int genNumber;
				
				try {
					genNumber = Integer.valueOf(textFieldGen.getText());
					if (genNumber < 0) {
						throw (new Exception());
					}
				} catch (Exception e) {
					JOptionPane.showMessageDialog(frame, "������� ����� ������������� �����", 
							"������������ ���� ���������� ���������", JOptionPane.ERROR_MESSAGE);
					return;
				}

                try {
                    Adapter.genSchedule(genNumber);
                    if (resultForm != null) {
                    	resultForm.frame.dispose();
                    }
                    resultForm = new ResultForm();
                    resultForm.frame.setVisible(true);
                } catch (CloneNotSupportedException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
		});
		final JButton buttonDel = new JButton("\u0423\u0434\u0430\u043B\u0438\u0442\u044C");
		buttonDel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				delTeacher();
			}
		});
		
		final JButton buttonAdd = new JButton("\u0414\u043E\u0431\u0430\u0432\u0438\u0442\u044C");
		buttonAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				comboBoxName.setEditable(true);
				comboBoxName.requestFocus();
				comboBoxName.setSelectedItem("");
				buttonAddName.setEnabled(true);
				textFieldPrio.setEditable(false);
				textFieldGen.setEditable(false);
				checkBoxWish1.setEnabled(false);
				checkBoxWish2.setEnabled(false);
				checkBoxWish3.setEnabled(false);
				checkBoxWish4.setEnabled(false);
				checkBoxWish5.setEnabled(false);
				checkBoxWish6.setEnabled(false);
				checkBoxWish7.setEnabled(false);
				checkBoxWish8.setEnabled(false);
				checkBoxWish9.setEnabled(false);
				checkBoxWish10.setEnabled(false);
				checkBoxWish11.setEnabled(false);
				checkBoxWish12.setEnabled(false);
				checkBoxWish13.setEnabled(false);
				checkBoxWish14.setEnabled(false);
				checkBoxWish15.setEnabled(false);
				checkBoxWish16.setEnabled(false);
				checkBoxWish17.setEnabled(false);
				checkBoxWish18.setEnabled(false);
				checkBoxWish19.setEnabled(false);
				checkBoxWish20.setEnabled(false);
				checkBoxWish21.setEnabled(false);
				checkBoxWish22.setEnabled(false);
				checkBoxWish23.setEnabled(false);
				checkBoxWish24.setEnabled(false);
				checkBoxWish25.setEnabled(false);
				checkBoxWish26.setEnabled(false);
				checkBoxWish27.setEnabled(false);
				checkBoxWish28.setEnabled(false);
				checkBoxWish29.setEnabled(false);
				checkBoxWish30.setEnabled(false);
				buttonGen.setEnabled(false);
				buttonAdd.setEnabled(false);
				buttonDel.setEnabled(false);
			}
		});
		
		buttonAddName.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addTeacher();
				
				comboBoxName.setEditable(false);
				buttonAddName.setEnabled(false);
				textFieldPrio.setEditable(true);
				textFieldGen.setEditable(true);
				checkBoxWish1.setEnabled(true);
				checkBoxWish2.setEnabled(true);
				checkBoxWish3.setEnabled(true);
				checkBoxWish4.setEnabled(true);
				checkBoxWish5.setEnabled(true);
				checkBoxWish6.setEnabled(true);
				checkBoxWish7.setEnabled(true);
				checkBoxWish8.setEnabled(true);
				checkBoxWish9.setEnabled(true);
				checkBoxWish10.setEnabled(true);
				checkBoxWish11.setEnabled(true);
				checkBoxWish12.setEnabled(true);
				checkBoxWish13.setEnabled(true);
				checkBoxWish14.setEnabled(true);
				checkBoxWish15.setEnabled(true);
				checkBoxWish16.setEnabled(true);
				checkBoxWish17.setEnabled(true);
				checkBoxWish18.setEnabled(true);
				checkBoxWish19.setEnabled(true);
				checkBoxWish20.setEnabled(true);
				checkBoxWish21.setEnabled(true);
				checkBoxWish22.setEnabled(true);
				checkBoxWish23.setEnabled(true);
				checkBoxWish24.setEnabled(true);
				checkBoxWish25.setEnabled(true);
				checkBoxWish26.setEnabled(true);
				checkBoxWish27.setEnabled(true);
				checkBoxWish28.setEnabled(true);
				checkBoxWish29.setEnabled(true);
				checkBoxWish30.setEnabled(true);
				buttonGen.setEnabled(true);
				buttonAdd.setEnabled(true);
				buttonDel.setEnabled(true);
			}
		});
		
		panelTeacher.add(buttonAdd, "2, 8, left, center");
		
		panelTeacher.add(buttonDel, "4, 8, left, center");
		
		JPanel panelGen = new JPanel();
		frame.getContentPane().add(panelGen, "1, 3, fill, fill");
		panelGen.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				ColumnSpec.decode("max(4dlu;default)"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel labelGen = new JLabel("\u041A\u043E\u043B-\u0432\u043E \u043F\u043E\u043A\u043E\u043B\u0435\u043D\u0438\u0439:");
		panelGen.add(labelGen, "2, 2, right, default");
		
		textFieldGen = new JTextField();
		textFieldGen.setText("100");
		panelGen.add(textFieldGen, "4, 2, left, default");
		textFieldGen.setColumns(5);
		
		
		panelGen.add(buttonGen, "6, 2, right, default");
	}

}
